package com.mj
{
	import com.mj.model.ConstCC;
	import com.mj.model.MjModel;
	import com.mj.scence.area.AreaScence;
	import com.mj.scence.game.GameScence;
	import com.notice.NoticeCC;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	
	public class mj extends Sprite
	{
		private var scenceSprite:Sprite;	//场景层
		private var gameUISprite:Sprite;	//游戏UI层,
		private var pendantSprite:Sprite;	//挂件层，放置功能入口图标
		private var popUpSprite:Sprite;	//弹出面板层
		private var msgSprite:Sprite;		//信息层
		
		private var areaScence:AreaScence;	//麻将区戏场景
		private var gameScence:GameScence;	//麻将游戏场景 
		
		
		
		
		
		public function mj()
		{
			super();
			this.addEventListener(Event.ADDED_TO_STAGE, addedToStage);	
		}
		
		private function addedToStage(evt:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, addedToStage);
			
			
			scenceSprite = new Sprite();
			scenceSprite.mouseEnabled = false;
			this.addChild(scenceSprite);
			gameUISprite = new Sprite();
			gameUISprite.mouseEnabled = false;
			this.addChild(gameUISprite);
			pendantSprite = new Sprite();
			pendantSprite.mouseEnabled = false;
			this.addChild(pendantSprite);
			popUpSprite = new Sprite();
			popUpSprite.mouseEnabled = false;
			this.addChild(popUpSprite);
			msgSprite = new Sprite();
			msgSprite.mouseEnabled = false;
			this.addChild(msgSprite);
			
			stage.addEventListener(Event.RESIZE, stageResize);
			NoticeCC.addListener(ConstCC.PAGE_TO_GAME_SCENCE, pageToGameScence);
			
			
			pageToArea();
			
		}
		
		private function pageToArea():void
		{
			while(scenceSprite.numChildren>0)
			{
				scenceSprite.removeChildAt(0);
			}
			if(areaScence == null)
				areaScence = new AreaScence();
			scenceSprite.addChild(areaScence.view);
			
		}
		
		private function pageToGameScence(areaId:int):void
		{
			while(scenceSprite.numChildren>0)
			{
				scenceSprite.removeChildAt(0);
			}
			if(gameScence == null)
				gameScence = new GameScence();
			gameScence.enterArea(areaId);
			scenceSprite.addChild(gameScence.view);
		}
		
		private function stageResize(evt:Event):void
		{
			
		}
		
		
	}
}